package com.js.purs.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.js.purs.mapper.PurConditionMapper;
import com.js.purs.domain.PurCondition;
import com.js.purs.service.IPurConditionService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 抽取条件Service业务层处理
 *
 * @author lzq
 * @date 20240704
 */
@Service
public class PurConditionServiceImpl implements IPurConditionService {
    @Autowired
    private PurConditionMapper purConditionMapper;

    /**
     * 查询抽取条件
     *
     * @param conditionId 抽取条件主键
     * @return 抽取条件
     */
    @Override
    public PurCondition selectPurConditionByConditionId(Long conditionId) {
        return purConditionMapper.selectPurConditionByConditionId(conditionId);
    }

    /**
     * 查询抽取条件列表
     *
     * @param purCondition 抽取条件
     * @return 抽取条件
     */
    @Override
    public List<PurCondition> selectPurConditionList(PurCondition purCondition) {
        return purConditionMapper.selectPurConditionList(purCondition);
    }

    /**
     * 新增抽取条件
     *
     * @param purCondition 抽取条件
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertPurCondition(List<PurCondition> purCondition) {
        System.out.println("长度:"+purCondition.size());
        int index = 0;
        if (purCondition.size() > 0) {
            PurCondition purCondition1 = purCondition.get(0);
            List<PurCondition> list = purConditionMapper.selectPurConditionList(purCondition1);
            for (PurCondition condition : list) {
                //删除
                purConditionMapper.deletePurConditionByConditionId(condition.getBindCode());
            }
            for (PurCondition con : purCondition) {
                //新增
                index = purConditionMapper.insertPurCondition(con);
            }
        }else{

            for (PurCondition con : purCondition) {
                //新增
                index = purConditionMapper.insertPurCondition(con);
            }
        }

        return index;
    }

    /**
     * 修改抽取条件
     *
     * @param purCondition 抽取条件
     * @return 结果
     */
    @Override
    public int updatePurCondition(PurCondition purCondition) {
        return purConditionMapper.updatePurCondition(purCondition);
    }

    /**
     * 批量删除抽取条件
     *
     * @param conditionIds 需要删除的抽取条件主键
     * @return 结果
     */
    @Override
    public int deletePurConditionByConditionIds(String[] conditionIds) {
        return purConditionMapper.deletePurConditionByConditionIds(conditionIds);
    }

    /**
     * 删除抽取条件信息
     *
     * @param bindCode 抽取条件主键
     * @return 结果
     */
    @Override
    public int deletePurConditionByConditionId(String bindCode) {
        return purConditionMapper.deletePurConditionByConditionId(bindCode);
    }
}
